package com.collect.tanzania.zhiScene.zhiWidget.zhiDialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.collect.tanzania.R;
import com.collect.tanzania.zhiUtils.StringUtil;

public class ZHIDialogPasswordUpdateSuccess extends Dialog {

    private final Context mContext;

    private TextView tv_dpus_title, tv_dpus_content, btn_dpus_cancel, btn_dpus_confirm;

    private String mContent;

    private ZHIDialogItemClickListener mZHIDialogItemClickListener;

    public static void showDialog(Context context, String content, ZHIDialogItemClickListener listener) {
        if (context == null) {
            return;
        }
        ZHIDialogPasswordUpdateSuccess dialog = new ZHIDialogPasswordUpdateSuccess(context);
        dialog.mContent = StringUtil.safeString(content);//percentTextToSourceText(content);
        dialog.mZHIDialogItemClickListener = listener;
        dialog.show();
    }

    public ZHIDialogPasswordUpdateSuccess(Context context) {
        super(context, R.style.CustomDialog);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_password_update_success);
        initView();
    }

    @Override
    public void show() {
        super.show();
        refreshViewData();
    }

    private void initView() {
        try {
            tv_dpus_content = findViewById(R.id.tv_dpus_content);
            btn_dpus_cancel = findViewById(R.id.btn_dpus_cancel);
            btn_dpus_confirm = findViewById(R.id.btn_dpus_confirm);

            btn_dpus_cancel.setOnClickListener(v -> dismiss());

            btn_dpus_confirm.setOnClickListener(v -> {
                mZHIDialogItemClickListener.onConfirmClick(btn_dpus_confirm.getText().toString().trim());
                dismiss();
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void refreshViewData() {
        if (!TextUtils.isEmpty(mContent)) {
            tv_dpus_content.setText(mContent);
        }
    }
}
